/**
 * 
 */
package org.dse.html;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * This class gives a simple implementation to the result container. It uses a
 * Map as the data structure. The key is the tag name and the object associated
 * with it is a set of values.
 * 
 * @author zhangchen
 * 
 */
public class TagResultContainerImpl implements TagResultContainer {

	private Map<String, HashSet<String>> result;

	/**
	 * The constructor. Initialize the data structure as an empty map.
	 */
	public TagResultContainerImpl() {
		result = new HashMap<String, HashSet<String>>();
	}

	/**
	 * If the tag name is firstly added, create a new entry of it. Else, get the
	 * result set from the map, and add the value.
	 * 
	 * @param tagName
	 *            the tag name
	 * @param value
	 *            the value associated with the tag name
	 */
	public void addResult(String tagName, String value) {
		HashSet<String> valueSet = result.get(tagName);
		if (valueSet == null) {
			valueSet = new HashSet<String>();
		}

		valueSet.add(value);
		result.put(tagName, valueSet);
	}

	/**
	 * Use the get method of map to get the result set.
	 * 
	 * @param tagName
	 *            the specific tag which the results associate with
	 * @return a Set containing the results
	 */
	public Set<String> getResult(String tagName) {
		return result.get(tagName);
	}
}
